//
//  SSTargetViewController.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/6/26.
//

import UIKit

class SSTargetViewController: UIViewController {
    @IBOutlet weak var item: SSTopBottomView!
    @IBOutlet weak var item2: SSTopBottomView!
    
    @IBOutlet weak var item3: SSTopBottomView!
    
    @IBOutlet weak var item4: SSTopBottomView!
    
    @IBOutlet weak var nameL: UILabel!
    
    
    var user = SSUser()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        title = "工作台"
        
        item.titleLab.text = "全部订单"
        item.imageV.image = UIImage(named: "all_order_icon")
        item.tag = 1
        let tap = UITapGestureRecognizer(target: self, action: #selector(hide(_:)))
        item.addGestureRecognizer(tap)
        
        item2.titleLab.text = "待服务"
        item2.imageV.image = UIImage(named: "unservice_icon")
        item2.tag = 2
        let tap2 = UITapGestureRecognizer(target: self, action: #selector(hide(_:)))
        item2.addGestureRecognizer(tap2)
        
        item3.titleLab.text = "我的薪资"
        item3.imageV.image = UIImage(named: "star_level_icon")
        item3.tag = 3
        let tap3 = UITapGestureRecognizer(target: self, action: #selector(hide(_:)))
        item3.addGestureRecognizer(tap3)
        
        item4.titleLab.text = "我的排班"
        item4.imageV.image = UIImage(named: "star_level_icon")
        item4.tag = 4
        let tap4 = UITapGestureRecognizer(target: self, action: #selector(hide(_:)))
        item4.addGestureRecognizer(tap4)
        
        
        nameL.text = user.userName
//        rightNav()
    
    }
    
    func rightNav() {
        let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
        btn.setImage(UIImage(named: "headset_nav"), for: .normal)
        btn .addTarget(self, action: #selector(rightNavAcion), for: .touchUpInside)
        let rightItem = UIBarButtonItem(customView: btn)
        self.navigationItem.rightBarButtonItem = rightItem
    }
    
    @objc func rightNavAcion(){
        datePickerAction()
//        navigationController?.pushViewController(SSOrderTimeSelectController(), animated: true)
        
//        navigationController?.pushViewController(SSNormalDetailController(), animated: true)
//        navigationController?.present(SSGetCouponViewController(), animated: true)
//        navigationController?.present(SSNormalTimeViewController(), animated: true)
        
//        pushViewController(SSGetCouponViewController(), animated: true)
    }
    
    func datePickerAction()
    {
        //创建日期选择器
        let datePicker = UIDatePicker(frame: CGRect(x:0, y:100, width:320, height:216))
        
        datePicker.backgroundColor = UIColor.red
        datePicker.datePickerMode = .date
        //将日期选择器区域设置为中文，则选择器日期显示为中文
        datePicker.locale = Locale(identifier: "zh_CN")
        //注意：action里面的方法名后面需要加个冒号“：”
        datePicker.addTarget(self, action: #selector(dateChanged),
                             for: .valueChanged)
        //设置日期选择器的样式
        datePicker.preferredDatePickerStyle = .wheels
//        if (@available(iOS 13.4, *))
//
//        {
//
//
//
//        } else {
//
//            // Fallback on earlier versions
//
//        }
//
//        //注意日期选择器的frame需要在设置样式后重新设置，在上面设置frame是没效果的
//        [self.datePicker setFrame:CGRectMake(0,40, KscreenWidth, 230)];
        self.view.addSubview(datePicker)
    }

    //日期选择器响应方法
    @objc func dateChanged(datePicker : UIDatePicker){
        //更新提醒时间文本框
        let formatter = DateFormatter()
        //日期样式
        formatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss"
        print(formatter.string(from: datePicker.date))
    }

    
    @objc func hide(_ tap:UITapGestureRecognizer){
        if tap.view?.tag == 1{
            UIViewController.current().navigationController?.pushViewController(SSOrderListViewController(), animated: true)
        }else if tap.view?.tag == 2{
            UIViewController.current().navigationController?.pushViewController(SSUnserviceOrderListController(), animated: true)
        }
        else if tap.view?.tag == 3{
            UIViewController.current().navigationController?.pushViewController(SSSalaryViewController(), animated: true)
        }
    else if tap.view?.tag == 4{
            UIViewController.current().navigationController?.pushViewController(SSOrderTimeSelectController(), animated: true)
    }
        
    }

    

}
